package com.zking.service.impl;

import com.zking.dto.AddressDto;
import com.zking.entity.Address;
import com.zking.repository.IAddressRepository;
import com.zking.service.IAddressService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class AddressServiceImpl implements IAddressService {
    private final IAddressRepository addressRepository;
    
    public List<AddressDto> getAddressByDeep(int deep) {
        List<Address> byDeep = addressRepository
                .findByDeep(deep);
        return byDeep
                .stream()
                .map(AddressDto::from)
                .collect(Collectors.toList());
    }
    
    public List<AddressDto> getAddressByParentId(int parentId) {
        return addressRepository
                .findByParentId(parentId)
                .stream()
                .map(AddressDto::from)
                .collect(Collectors.toList());
    }
}
